<!--
 * @Description: 活动管理列表
 * @Author: liyujie
 * @Date: 2021/2/23
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/2/23
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    平台大促
                </div>
                <el-button
                    type="primary"
                    size="medium"
                    icon="el-icon-plus"
                    @click="handleRoute('activityManageEdit', {no: '', type: 'add', status: ''})"
                >
                    创建活动
                </el-button>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        活动信息
                    </p>
                    <el-input
                        placeholder="搜索活动编号，活动名称"
                        v-model="filterData.keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 400px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->

            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="tempLateName"
                    class="data-table"
                    v-loading="tableLoading"
                >
                    <el-table-column
                        label="序号"
                        align="center"
                        width="80"
                        type="index"
                    />
                    <el-table-column
                        prop="activity_no"
                        label="活动编号"
                        show-overflow-tooltip
                        align="left"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="title"
                        label="活动主题"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="商家报名时间"
                        align="left"
                        :formatter="emptyFormatter"
                        min-width="160"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.apply_start_time * 1000 | dateFormatter('yyyy/MM/dd') }} -
                            {{ scope.row.apply_end_time * 1000 | dateFormatter('yyyy/MM/dd') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="活动预热时间"
                        align="left"
                        :formatter="emptyFormatter"
                        min-width="160"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.preheating_start_time * 1000 | dateFormatter('yyyy/MM/dd') }} -
                            {{ scope.row.preheating_end_time * 1000 | dateFormatter('yyyy/MM/dd') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="活动进行时间"
                        align="left"
                        :formatter="emptyFormatter"
                        min-width="160"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.activity_start_time * 1000 | dateFormatter('yyyy/MM/dd') }} -
                            {{ scope.row.activity_end_time * 1000 | dateFormatter('yyyy/MM/dd') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="活动进度"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.status | statusFilter }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        align="left"
                        width="200"
                    >
                        <template slot-scope="scope">
                            <div class="option-btn-group">
                                <el-button
                                    type="text"
                                    size="medium"
                                    @click="handleRoute('activityManageEdit', {no: scope.row.activity_no, type: 'detail', status: scope.row.status})"
                                >
                                    查看
                                </el-button>
                                <el-button
                                    type="text"
                                    size="medium"
                                    :disabled="scope.row.can_edit === 0"
                                    @click="handleEdit(scope.row)"
                                >
                                    编辑
                                </el-button>
                                <el-button
                                    type="text"
                                    size="medium"
                                    @click="toVerifyList(scope.row)"
                                    v-if="scope.row.status"
                                >
                                    {{ scope.row.status > 2 ? '查看商品' : '审核商品' }}
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->

            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <!--<el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />-->
            </div>
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'ActivityManageList',
    mixins: [back],
    components: {},
    data() {
        return {
            filterData: {
                // 活动信息
                keyword: '',
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
        };
    },
    computed: {},
    watch: {},
    filters: {
        statusFilter(val) {
            // 0:未开始,1:报名中,2:报名结束,3:预热中,4:预热结束,5:活动中,6:活动结束
            switch (val) {
                case 0:
                    return '报名未开始';
                case 1:
                    return '报名进行中';
                case 2:
                    return '报名已结束';
                case 3:
                    return '预热进行中';
                case 4:
                    return '预热已结束';
                case 5:
                    return '活动进行中';
                case 6:
                    return '活动已结束';
                default:
                    return '--';
            }
        },
    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '商城'}, {title: '平台大促'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {

            this.tableLoading = true;
            let params = { ...this.filterData };

            this.$post('/student/activity%5Cget_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 编辑
         * @param row
         * @returns {boolean}
         */
        handleEdit(row) {
            if(!this.authResult.auth_edit) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            this.handleRoute('activityManageEdit', {no: row.activity_no, type: 'edit', status: row.status});
        },

        /**
         * 跳转审核商品页面
         * @param row
         */
        toVerifyList(row) {
            if(row.activity_no.slice(0, 3) === 'a20') {
                this.handleRoute('activeGoodsVerify');
            } else {
                // 分会场审核商品列表
                this.handleRoute('schoolSeasonGoodsVerify', {activity_no: row.activity_no, title: row.title});
            }
        }
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 0 24px;
            margin-top: 12px;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
                .query-button  {
                    width: 84px;
                    height: 36px;
                    background: #FFFFFF;
                    border-radius: 4px;
                    border: 1px solid #1890FF;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #1890FF;
                    margin-right: 12px;
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 24px;
            flex: 1;
            height: 0;
        }

        // 表格
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }

        /* 分页 */
        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
}
</style>
